package ${serviceImplUrl};


import com.erayt.bds.api.BdsFeignClientApi;
import com.erayt.bds.utils.StringTools;
import com.erayt.bds.utils.DateTools;
import ${entityUrl}.${entityName};
import ${voUrl}.${entityName}Vo;
import com.erayt.ecas.bean.User;
import ${daoUrl}.${entityName}Mapper;
import ${serviceUrl}.${entityName}Service;
import com.erayt.solar.QueryParam;
import com.erayt.solar.db.query.SolarPage;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**   
 * @description:TODO(${entityComment}服务实现)
 * @company erayt
 * @author ${author}
 * @date ${createTime}
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ${entityName}ServiceImpl implements ${entityName}Service  {

    private final static Logger logger = LoggerFactory.getLogger(${entityName}ServiceImpl.class);

	@Resource
	private ${entityName}Mapper ${objectName}Mapper;

	@Resource
    private BdsFeignClientApi bdsFeignClientApi;

    @Override
    public SolarPage<${entityName}Vo> queryPageByParam(QueryParam queryParam) {
        return ${objectName}Mapper.queryPageByParam(queryParam);
    }

    @Override
    public ${entityName}Vo selectByPrimaryKey(User user, String primaryKey) {
        return ${objectName}Mapper.selectByPrimaryKey(primaryKey);
    }

    @Override
    public List<${entityName}Vo> selectAllData() {
        logger.debug("查询全部信息-开始");
        List<${entityName}Vo> list = ${objectName}Mapper.selectAllData();
        logger.debug("查询全部信息-结束");
        return list;
    }

    @Override
    public void insert(User user, ${entityName} ${objectName}) {
        logger.debug("新增${entityComment}-开始");
        // 获取唯一主键
        String ${keyProperty} = bdsFeignClientApi.getKey(${entityName}.class.getSimpleName());
        ${objectName}.set${keyPropertyUp}(${keyProperty});
        DateTools.setUserAndTime(${objectName},user,Boolean.TRUE);
        ${objectName}Mapper.insert(${objectName});
        logger.debug("新增${entityComment}-结束");
    }

    @Override
    public void batchInsert(List<${entityName}> list) {
        logger.debug("批量插入情景定义-开始");
        Map insertMap = new HashMap(2);
        // 批量插入基准表
        insertMap.put("list",list);
        ${objectName}Mapper.batchInsert(insertMap);
        logger.debug("批量插入情景定义-结束");
    }

    @Override
    public void delete(User user, String primaryKey) {
        logger.debug("删除${entityComment}-开始");
        ${objectName}Mapper.deleteByPrimaryKey(primaryKey);
        logger.debug("删除${entityComment}-结束");
    }

    @Override
    public void update(User user, ${entityName} ${objectName}) {
        logger.debug("修改${entityComment}-开始");
        DateTools.setUserAndTime(${objectName},user,Boolean.FALSE);
        ${objectName}Mapper.updateByPrimaryKey(${objectName});
        logger.debug("修改${entityComment}-结束");
    }

    @Override
    public Map<Integer, String[]> getComboboxData() {
        // String[] statusType = new String[]{DataStatusEnum.NEW.getName(), DataStatusEnum.ENABLE.getName(), DataStatusEnum.DISABLE.getName()};
        // String[] yesOrNo = new String[]{YesNoEnum.YES.getChsName(), YesNoEnum.NO.getChsName()};
        Map<Integer, String[]> mapDropDown = new HashMap<>(4);
        // 这里的key值 对应导出列的顺序 从0开始
        // 将第3列单元格设置成statusType 下拉框
        // mapDropDown.put(2, statusType);
        // 将第4列单元格设置成yesOrNo 下拉框
        // mapDropDown.put(3, yesOrNo);
        return mapDropDown;
    }
    @Override
    public List<${entityName}> createUserExampleData() {
        List<${entityName}> list = new ArrayList<>();
        ${entityName} ${objectName} = new ${entityName}();
        list.add(${objectName});
        return list;
    }
    

    @Override
    public <T> void batchProcess(List<T> list) {
        List<${entityName}> newList = (List<${entityName}>) list;
        for (${entityName} ${objectName} : newList) {
            if (StringTools.isEmpty(${objectName}.get${keyPropertyUp}())){
                String ${keyProperty} = bdsFeignClientApi.getKey(${entityName}.class.getSimpleName());
                ${objectName}.set${keyPropertyUp}(${keyProperty});
            }
        }
        this.batchInsert(newList);
    }
}